package com.my.hzb.ctrl;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.my.hzb.mq.MqSender;
import com.my.hzb.service.TestService;

@Controller
public class HomeCtrl {

	@Autowired
	private TestService testService;
//	@Autowired
//	private MqSender mqSender;
	
	@RequestMapping("/index")
	public String index(HttpServletRequest request){
		request.setAttribute("list", testService.getList());
		return "/index";
	}
	@RequestMapping("/index2")
	public String index2(HttpServletRequest request){
//		mqSender.sendMessage("hello world!");
		return "/index2";
	}
	@RequestMapping("/index3")
	public String index3(HttpServletRequest request,HttpServletResponse response){
		Cookie co = new Cookie("test","{hello world!}");
		co.setDomain(".www.baidu.com");
//		co.setDomain(".houzhangbo.com");
		response.addCookie(co);
		return "/index3";
	}
	@RequestMapping("/testt1")
	@ResponseBody
	public String testt1(HttpServletRequest request){
		long start = System.currentTimeMillis();
		try {
			Thread.sleep(15000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println((System.currentTimeMillis()-start));
		return ""+(System.currentTimeMillis()-start);
	}
}
